package cn.ronghuanet.base.service.impl;

import cn.ronghuanet.base.mapper.BaseMapper;
import cn.ronghuanet.base.query.BaseQuery;
import cn.ronghuanet.base.service.IBaseService;
import cn.ronghuanet.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class IBaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Transactional
    @Override
    public void update(T role) {
        mapper.update( role);
    }
    @Transactional
    @Override
    public void insert(T role) {
        mapper.insert( role);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        mapper.delete( id);
    }
    @Transactional
    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete( ids);
    }

    @Override
    public T selectById(Long id) {
        return mapper.selectById( id);
    }

    @Override
    public List<T> selectAll() {
        return mapper.selectAll( );
    }

    @Override
    public PageInfo<T> queryPage(BaseQuery baseQuery) {
        // 查询条数
        Long integer = mapper.countTotal(baseQuery);
        if (integer == 0){
            return  new PageInfo<>();
        }
        // 查询数据
        List<T> list = mapper.queryPage(baseQuery);
        // 封装对象
        // 返回数据
        return new PageInfo<T>(integer,list);
    }
}
